"""
@author: xxw
@file: homework_tree.py
@time: 2023/3/31 15:15
"""
# D:\Program Files\Python39
# os.path.isfile()和os.path.isdir() 用来检验是文件还是目录

import os
path = input("请输入文件路径:")
depth = 0
def tree(pwd,depth):
    name = os.listdir(pwd)
    for i in name:
        print("   " * depth, end="")
        if os.path.isdir(os.path.join(pwd, i)):
            print("|----", i)
            tree(os.path.join(pwd, i), depth+1)
        elif os.path.isfile(os.path.join(pwd, i)):
            print("|----", i)

# 判断路径是否存在
if os.path.exists(path):
    tree(path, depth)
else:
    print("该路径不存在")





